var app = getApp()
Page({
    data: {
        data: '',
        tel: '',
        id: '',
        search: ''
    },

    // formid
    formSubmit: function(e) {
        var formId = e.detail.formId
        var that = this;
        wx.getStorage({
            key: 'user',
            success: function(res) {
                wx.request({
                    url: app.url.requestUrl + '/user/collect_formid',
                    method: 'POST',
                    data: {
                        openid: res.data.openid,
                        token: res.data.token,
                        formid: formId
                    },
                    success: function(res) {
                        if (res.data.code == 1) {

                        }
                    }
                })
            }
        })
    },

    tel(e) {
        this.setData({
            search: e.detail.value
        })
    },
    radioChange: function(e) {
        var id = e.detail.value;
        this.setData({
            id: id
        })
    },
    search: function(e) {
        var that = this;
        wx.getStorage({
            key: 'user',
            success: function(res) {
                wx.request({
                    url: app.url.requestUrl + '/user/search_user',
                    method: 'POST',
                    data: {
                        openid: res.data.openid,
                        token: res.data.token,
                        search: that.data.search
                    },
                    success: function(res) {
                        if (res.data.code == 1) {
                            that.setData({
                                data: res.data.data
                            })
                        } else {
                            wx.showToast({
                                image: '../../img/icon-prompt.png',
                                title: res.data.msg,
                            })
                        }
                    }
                })
            }
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

    },
    add: function(e) {
        var that = this;
        var id = this.data.id;
        console.log(id)
        wx.getStorage({
            key: 'user',
            success: function(res) {
                wx.request({
                    url: app.url.requestUrl + '/user/add_manage',
                    method: 'POST',
                    data: {
                        openid: res.data.openid,
                        token: res.data.token,
                        user_id: parseInt(that.data.id)
                    },
                    success: function(res) {
                        if (res.data.code == 1) {
                            wx.showToast({
                                title: res.data.msg,
                            })
                            setTimeout(function() {
                                wx.hideLoading();
                                wx.navigateBack({
                                    delta: 1
                                })
                            }, 1000)
                            // that.onLoad()

                        }else{
                          wx.showToast({
                            title: res.data.msg,
                          })
                        }

                    }
                })
            }
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})